
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>员工</title>
    <link rel="stylesheet" type="text/css" href="/static/plugins/easyui/themes/material/easyui.css">
    <link rel="stylesheet" type="text/css" href="/static/plugins/easyui/themes/icon.css">
    <script type="text/javascript" src="/static/plugins/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/static/plugins/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/static/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script>
        $(function () {
            //编辑对话框
            $("#stock_dig").dialog({
                width: 400,
                height: 330,
                closed: true,
                cache: false,
                modal: true,
                buttons:'#stock_dig_btn',
                onClose:function () {
                    //关闭dialog,清空表单数据
                    $("#stock_form").form("clear");
                }
            })

            $('#stock_dg').datagrid({
                url:'/stock/selectAll.do',
                fitColumns:true,
                fit:true,
                nowrap:true,
                pagination:true,
                singleSelect:true,
                toolbar:"#stock_tb",
                pageSize:10,
                rownumbers:true,
                pageList:[10,20,30],
                columns:[[
                    {field:'sn',title:'商品编号',width:100},
                    {
                        field:'productname',title:'商品名称',width:100,formatter: function (value) {
                            return "<span title='" + value + "'>" + value + "</span>";
                        }
                    },
                    {field:'number',title:'库存数量',width:100},
                    {field:'newnumber',title:'盘点差异',width:100},
                    {field:'checkDate',title:'最近盘点时间',width:100}
                ]]
            });
            
        })
        /*提交表单*/
        function submitForm() {
            $('#stock_form').form({
                url:'/stock/updateNewNumber.do',
                success:function(data){
                    var data =  $.parseJSON(data);
                    if (data.success) {
                        $.messager.alert('温馨提示','盘点成功','info',function () {

                            closeWin();
                            $('#stock_dg').datagrid("reload");
                        });
                    }
                    else{
                        $.messager.alert('温馨提示',data.msg);
                        closeWin();
                    }
                }
            });

            $('#stock_form').submit();
        }


        /*盘点*/
        function inventory() {
            var tr = $('#stock_dg').datagrid("getSelected");
            if (!tr) {
                //没有选中
                $.messager.alert('温馨提示',"至少选中一条数据");
                return;
            }

            $("#stock_dig").dialog("setTitle","盘点库存");
            $("#stock_dig").dialog("open");
            //数据回显
            tr["productName"] = tr.productName;
            tr["productId"] = tr.productId;
            tr["sn"] = tr.sn;
            $('#stock_form').form("load",tr);
        };




        //盘点明细
        //123
        function inventoryItem() {
            var tr = $('#stock_dg').datagrid("getSelected");
            if (!tr) {
                //没有选中
                $.messager.alert('温馨提示',"至少选中一条数据");
                return;
            }


                    $("#item_dg").datagrid({
                        fitColumns:true,
                        url:"/stock/selectItmesById.do?id="+tr.id,
                        fit:true,
                        nowrap:true,
                        pagination:true,
                        singleSelect:true,
                        pageSize:10,
                        rownumbers:true,
                        pageList:[10,20,30],
                        columns:[[
                            {field:'productId',title:'商品编号',width:100},
                            {
                                field:'productname',title:'商品名称',width:100,formatter: function (value) {
                                    return "<span title='" + value + "'>" + value + "</span>";
                                }
                            },
                            {field:'number',title:'库存数量',width:100},
                            {field:'newnumber',title:'盘点差异',width:100},
                            {field:'checkDate',title:'最近盘点时间',width:100}
                        ]]
                    });


            $("#items_dig").dialog("open")


        }

        /*刷新*/
        function reloadwin() {
            $('#stock_dg').datagrid("reload");
        }

        /*关闭对话框*/
        function closeWin() {
            $("#stock_dig").dialog("close")
            $('#stock_form').form("clear")
        }


    </script>
</head>
<body>

<table id="stock_dg"></table>

<!--dialog和dialog中的盘点明细datagrid -->
<div id="items_dig"  class="easyui-dialog" title="您选择的商品的库存明细是："
     data-options="iconCls:'icon-save',resizable:true,modal:true,closed:true"
     style="width:700px;height:400px; padding: 5px 2px"
     resizable:true,modal:true>
    <table id="item_dg"></table>
</div>
<div id="stock_tb" >
    <a class="easyui-linkbutton" onclick="inventory()" data-options="iconCls:'icon-tip',text:'盘点'"></a>
    <a class="easyui-linkbutton" onclick="reloadwin()" data-options="iconCls:'icon-reload',text:'刷新'"></a>
    <a class="easyui-linkbutton" onclick="inventoryItem()" data-options="iconCls:'icon-search',text:'盘点明细'"></a>
</div>
<div id="stock_dig">
    <form id="stock_form" >
        <table align="center" >
            <input type="hidden" name="id">
            <br>
            <br>

            <tr>
                <td>商品名称:</td>
                <td>
                    <input type="hidden" value="" name="productId" >
                    <input class="easyui-combobox" type="text" name="productname" readonly
                           data-options="url:'/product/selectAll.do',textField:'productName',valueField:'id',panelHeight:'auto'"/>
                </td>
            </tr>

            <tr>
                <td>商品编号:</td>
                <td>
                    <input class="easyui-combobox" type="text" name="sn" readonly
                           data-options="url:'/product/selectAll.do',textField:'productSn',valueField:'id',panelHeight:'auto'"/>
                </td>
            </tr>

            <tr>
                <td>库存数量:</td>
                <td>
                    <input class="easyui-textbox" type="text" name="number" readonly/>
                </td>
            </tr>

            <tr>
                <td>盘点差异:</td>
                <td>
                    <input class="easyui-textbox" type="text" name="newnumber" />
                </td>
            </tr>
        </table>

    </form>
</div>
<!--对话框底部工具栏-->
<div id="stock_dig_btn">
    <a class="easyui-linkbutton" onclick="submitForm()" data-options="iconCls:'icon-save',text:'确认盘点'"></a>
    <a class="easyui-linkbutton" onclick="closeWin()" data-options="iconCls:'icon-cancel',text:'取消'"></a>
</div>

</body>
</html>
